package com.mk.web.basic.lock;

/**
 * Created by WangChen on 2019/1/8 11:24.
 */
public class LockConstant {

    String s1 = "hello";
    String s2 = new String("hello"); // new关键字，一定是在堆中创建一个新的对象。
    String s3 = "hello";
    Integer i1 = 1000000;
    Integer i2 = 1000000;
    void m1(){
        synchronized (i1) {
            System.out.println("m1()");
            while(true){

            }
        }
    }

    void m2(){
        synchronized (i2) {
            System.out.println("m2()");
            while(true){

            }
        }
    }

    public static void main(String[] args) {
        final LockConstant t = new LockConstant();
        new Thread(new Runnable() {
            @Override
            public void run() {
                t.m1();
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                t.m2();
            }
        }).start();
    }
}
